<?php
/**
 * Created by Zhy
 * User: Zhy
 * Date: 2020/2/13
 * Time: 14:39
 */

namespace app\admin\controller;


use think\Db;
use think\Request;

class League extends Base
{
    /**
     * 首页
     */
    public function index(){
        if(request()->isAjax()){
            extract(input());
            $where = [];
            if(isset($user_name) && $user_name != ''){
                $where['st_name_cn|st_country'] = ['like', '%' . $user_name . '%'];
            }
            if(isset($st_fid) && $st_fid != ''){
                $where['st_fid'] = $st_fid;
            }
            $NowPage = input('page') ? input('page') : 1;
            $limits = input("limit") ? input("limit") : 10;
            $count = Db::table('up_sport_team')
                ->where($where)
                ->count();// 获取总条数
            $lists = Db::table('up_sport_team')
                ->where($where)
                ->page($NowPage,$limits)
                ->order('st_hot desc')
                ->select();
            return json(['code' => 220, 'msg' => '', 'count' => $count, 'data' => $lists]);
        }
        return $this->fetch();
    }

    /**
     * 热门
     * @return \think\response\Json
     */
    public function hotYes(){
        $st_id = input('id');
        $res = Db::table('up_sport_team')->where('st_id',$st_id)->setField('st_hot',2);
        if($res){
            return json(['code' => 200, 'msg' => '成功']);
        }else{
            return json(['code' => 100, 'msg' => '失败']);
        }
    }
    /**
     * 取消热门
     * @return \think\response\Json
     */
    public function hotNo(){
        $st_id = input('id');
        $res = Db::table('up_sport_team')->where('st_id',$st_id)->setField('st_hot',1);
        if($res){
            return json(['code' => 200, 'msg' => '成功']);
        }else{
            return json(['code' => 100, 'msg' => '失败']);
        }
    }
}